<template>
  <div class="appointment-entry">
    <!-- 导航栏 -->
    <van-nav-bar
      title="预约进场"
      left-text="返回"
      left-arrow
      @click-left="goBack"
      class="custom-nav"
    />

    <!-- 页面内容 -->
      <div class="content">
        <!-- 提示信息 -->
        <div class="prompt-message">
          <div class="prompt-header">
            <van-icon name="info-o" size="24" color="#667eea" />
            <span class="prompt-title">预约信息核对</span>
          </div>
          <p class="prompt-text">请核对以下预约信息，确认无误后点击底部按钮完成预约</p>
          <p class="prompt-hint">确认后将进入下一步流程，请确保信息准确</p>
        </div>

        <!-- 预约信息卡片 -->
      <div class="info-card">
        <div class="info-item">
          <div class="info-label">预约码</div>
          <div class="info-value appointment-code">{{ appointmentInfo.appointmentCode }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">类型</div>
          <div class="info-value">{{ appointmentInfo.type }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">编号</div>
          <div class="info-value">{{ appointmentInfo.number }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">客户码</div>
          <div class="info-value">{{ appointmentInfo.customerCode }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">客户</div>
          <div class="info-value">{{ appointmentInfo.customer }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">序号</div>
          <div class="info-value">{{ appointmentInfo.serialNumber }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">产品名</div>
          <div class="info-value">{{ appointmentInfo.productName }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">规格</div>
          <div class="info-value">{{ appointmentInfo.specification }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">数量</div>
          <div class="info-value">{{ appointmentInfo.quantity }}</div>
        </div>
      </div>

      <!-- 确认按钮 -->
      <div class="button-section">
        <van-button
          round
          block
          type="primary"
          class="confirm-button"
          @click="confirmAppointment"
        >
          确认预约
        </van-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { showToast, showSuccessToast } from 'vant'

const router = useRouter()

// 预约信息数据
const appointmentInfo = reactive({
  appointmentCode: 'DEF1760076887104',
  type: '销售单',
  number: 'XSJH2507300001',
  customerCode: '8256',
  customer: '大庆砂酸厂',
  serialNumber: '1',
  productName: '散装20-40',
  specification: '20-40',
  quantity: '100.00'
})

// 返回首页
const goBack = () => {
  router.push('/')
}

// 确认预约
const confirmAppointment = async () => {
  try {
    // 模拟API请求
    await new Promise(resolve => setTimeout(resolve, 1000))
    
    // 显示成功消息
    showSuccessToast('预约确认成功')
    
    // 跳转回首页
    setTimeout(() => {
      router.push('/')
    }, 1500)
  } catch (error) {
    showToast('确认失败，请重试')
  }
}
</script>

<style scoped>
.appointment-entry {
    min-height: 100vh;
    background-color: #f8f9fa;
    padding-bottom: 20px;
    overflow-y: auto;
  }

  /* 提示信息 */
  .prompt-message {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(102, 126, 234, 0.1);
  }

  .prompt-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
  }

  .prompt-icon {
    margin-right: 8px;
  }

  .prompt-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 18px;
  }

  .prompt-text {
    margin: 8px 0;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
  }

  .prompt-hint {
    color: #999;
    font-size: 12px;
    line-height: 1.3;
    margin: 0;
  }

  /* 自定义导航栏 */
.custom-nav {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.custom-nav :deep(.van-nav-bar__title) {
  color: white;
  font-weight: 600;
}

.custom-nav :deep(.van-nav-bar__text) {
  color: white;
}

.custom-nav :deep(.van-icon) {
  color: white;
}

/* 页面内容 */
.content {
  padding: 16px;
  overflow-y: auto;
}

/* 信息卡片 */
.info-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
}

/* 信息项 */
.info-item {
  display: flex;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.info-item:last-child {
  border-bottom: none;
}

.info-label {
  flex: 0 0 80px;
  color: #666;
  font-size: 15px;
  line-height: 22px;
}

.info-value {
  flex: 1;
  color: #333;
  font-size: 15px;
  line-height: 22px;
  text-align: right;
  word-break: break-all;
}

/* 预约码特殊样式 */
.appointment-code {
  color: #f97316;
  font-weight: 600;
  letter-spacing: 1px;
}

/* 按钮区域 */
.button-section {
  padding: 0 16px;
}

/* 确认按钮 */
.confirm-button {
  height: 48px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.confirm-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

/* 响应式优化 */
@media screen and (max-width: 375px) {
  .content {
    padding: 12px;
  }
  
  .info-item {
    padding: 12px 14px;
  }
  
  .info-label {
    flex: 0 0 70px;
    font-size: 14px;
  }
  
  .info-value {
    font-size: 14px;
  }
  
  .button-section {
    padding: 0 12px;
  }
}

/* 加载动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.info-card {
  animation: fadeInUp 0.6s ease forwards;
}

.button-section {
  animation: fadeInUp 0.6s ease 0.2s forwards;
  opacity: 0;
}
</style>